package com.atguigu.search.controller;

import com.atguigu.search.service.SearchService;
import com.atguigu.search.vo.SearchParam;
import com.atguigu.search.vo.SearchResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

  @Resource
  private SearchService searchService;

  @GetMapping("/search.html")
  public String getSearchPage(SearchParam searchParam, Model model, HttpServletRequest request) {
    searchParam.set_queryString(request.getQueryString());
    SearchResult result = searchService.getSearchResult(searchParam);
    model.addAttribute("result", result);
    return "search";
  }
}
